package com.ceair.flight.refund.service.impl;

import com.ceair.flight.refund.dto.appmoblie.RefundApplyDeputyDto;
import com.ceair.flight.refund.dto.appmoblie.RefundApplyDto;
import com.ceair.flight.refund.dto.appmoblie.RefundPayDto;
import com.ceair.flight.refund.dto.appmoblie.RefundTktDto;
import com.ceair.flight.refund.dto.external.PayProductDto;
import com.ceair.flight.refund.location.dao.IFlightOrderDao;
import com.ceair.flight.refund.location.dao.IPayDao;
import com.ceair.flight.refund.location.dao.IRefundApplyDao;
import com.ceair.flight.refund.location.dao.IRefundApplyDeputyDao;
import com.ceair.flight.refund.location.dao.IRefundPayDao;
import com.ceair.flight.refund.location.dt.enums.PayResponseCodeEnum;
import com.ceair.flight.refund.location.dt.enums.PaymentStatusEnum;
import com.ceair.flight.refund.location.dt.enums.RefundTypeEnum;
import com.ceair.flight.refund.location.dt.enums.TktNature;
import com.ceair.flight.refund.location.model.FlightOrderDO;
import com.ceair.flight.refund.location.model.PayDO;
import com.ceair.flight.refund.location.model.RefundApplyDO;
import com.ceair.flight.refund.location.model.RefundPayDO;
import com.ceair.flight.refund.location.model.RefundTktDO;
import com.ceair.flight.refund.location.service.IRefundLocationService;
import com.ceair.flight.refund.service.IRefundPayService;
import com.ceair.flight.refund.util.BeanCopyUtils;
import com.ceair.flight.refund.util.CeairUtil;
import com.ceair.flight.refund.util.DBUtil;
import com.ceair.flight.refund.util.StringUtil;
import com.ceair.muservice.basicdata.dto.channel.ChannelManageDto;
import com.ceair.muservice.basicdata.feign.util.ChannelUtil;
import com.ceair.muservice.common.exception.MuServiceException;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("refundPayServiceImpl")
@Path("/")
public class RefundPayServiceImpl implements IRefundPayService {

    private static final Logger logger = LoggerFactory.getLogger(RefundPayServiceImpl.class);
    @Autowired
    private IRefundApplyDao refundApplyDao;
    @Autowired
    private IPayDao payDao;
    @Autowired
    private IFlightOrderDao flightOrderDao;
    @Autowired
    private IRefundPayDao refundPayDao;
    @Autowired
    private IRefundApplyDeputyDao refundApplyDeputyDao;

    @Autowired
    @Qualifier("dbUtil")
    private DBUtil dbUtil;

    @Autowired
    private IRefundLocationService refundLocationService;

    @POST
    @Path("/doBatchRefundPay")
    @Override
    public void doBatchRefundPay() throws MuServiceException {
        logger.info("批量退款开始！");
        RefundApplyDto refundApplyDto = new RefundApplyDto();
        refundApplyDto.setStatuses(new String[] { "401", "409" });
        try {
            doBatchRefundPayFlight(refundApplyDto);
            doBatchRefundPayAncillary(refundApplyDto);
        }catch (Exception e){
            logger.error("批量退款异常：",e);
        }

        logger.info("批量退款结束！");
    }

    @Override
    public List<RefundPayDto> doBatchUploadRefundPay(RefundPayDto refundPayDto) throws MuServiceException {

        return getRfdPayList(refundPayDto);
    }

    private List<RefundPayDto> getRfdPayList(RefundPayDto refundPayDto){
        List<RefundPayDO> refundPayDOS = refundPayDao.getRefdPayList(refundPayDto);
        List<RefundPayDto> refundPayDtoList = new ArrayList<RefundPayDto>();
        if (!CollectionUtils.isEmpty(refundPayDOS)){
            for (RefundPayDO refundPayDO:refundPayDOS){
                RefundPayDto refundPayDto1 = this.trans2Dto(refundPayDO,RefundPayDto.class);
                refundPayDtoList.add(refundPayDto1);
            }
        }
        return refundPayDtoList;
    }

    private RefundPayDto trans2Dto(RefundPayDO model, Class<RefundPayDto> clazz) {
        try {
            return (RefundPayDto) BeanCopyUtils.copy(model, clazz);
        } catch (Exception e) {
            logger.error("类型转换异常：",e);
            return null;
        }
    }

    /**
     *
     * @param refundApplyDto 退机票和Emd
     */
    private void doBatchRefundPayFlight(RefundApplyDto refundApplyDto) {
        List<RefundApplyDto> refundApplyList =refundApplyDao.getRefundDtoApplyList(refundApplyDto);
        if (refundApplyList == null || refundApplyList.isEmpty()) {
            logger.info("没有可退款的机票退票单！");
            return;
        }
        List<Long> refundApplyIdList = new ArrayList<Long>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        List<RefundPayDO> refundPays = new ArrayList<RefundPayDO>();
        for (int i = 0; i < refundApplyList.size(); i++) {
            RefundApplyDto refundApply = refundApplyList.get(i);
            String flightOrderNo = refundApply.getRefundTkt().getFlightOrderNo();
            RefundTktDto refundTkt = refundApply.getRefundTkt();
            Integer refundType = RefundTypeEnum.REFUND_TICKET.getCode();
            List<PayDO> needToRefundPayDtoList = new ArrayList<PayDO>();
            getNeedToRefundPayDto(flightOrderNo, needToRefundPayDtoList);
            if (refundTkt != null) {
                if (refundTkt.getTktNature() != null && TktNature.EMD.getCode().equals(refundTkt.getTktNature())) {
                    refundType = RefundTypeEnum.REFUND_EMD.getCode();
                }
                //如果是改期订单退款就要找原始机票订单退款
                if (refundTkt.getTktNature() != null && TktNature.RESCHEDULE.getCode().equals(refundTkt.getTktNature())) {
                    FlightOrderDO flightOrderDto = new FlightOrderDO();
                    String orderNo = refundApply.getRefundTkt().getOrderNo();
                    flightOrderDto.setOrderNo(orderNo);
                    List<FlightOrderDO> flightOrderDtoList = flightOrderDao.getFlightOrderDOs(flightOrderDto);
                    if (flightOrderDtoList != null && !flightOrderDtoList.isEmpty()) {
                        FlightOrderDO rescheduleFlightOrderDto = null;
                        FlightOrderDO oldFlightOrderDto = null;
                        String queryFlightOrderNo = flightOrderNo;
                        do {
                            for (int j = 0; j < flightOrderDtoList.size(); j++) {
                                if (queryFlightOrderNo.equals(flightOrderDtoList.get(j).getFlightOrderNo())) {
                                    rescheduleFlightOrderDto = flightOrderDtoList.get(j);
                                }
                            }

                            for (int k = 0; k < flightOrderDtoList.size(); k++) {
                                if (flightOrderDtoList.get(k).getFlightOrderNo().equals(rescheduleFlightOrderDto.getOldRecId())) {
                                    oldFlightOrderDto = flightOrderDtoList.get(k);
                                }
                            }
                            queryFlightOrderNo = oldFlightOrderDto.getFlightOrderNo();
                            getNeedToRefundPayDto(queryFlightOrderNo, needToRefundPayDtoList);
                        } while (StringUtils.isNotBlank(oldFlightOrderDto.getOldRecId()));
                    }
                }
            }
            if (refundApply.getRefundAmount() != null && refundApply.getRefundAmount().compareTo(BigDecimal.ZERO) > 0) {
                BigDecimal remainRefundAmount = refundApply.getRefundAmount();
                for (int j = 0; j < needToRefundPayDtoList.size(); j++) {
                    PayDO payDto = needToRefundPayDtoList.get(j);
                    PayDO payDO = (PayDO) BeanCopyUtils.copy(payDto, PayDO.class);
                    BigDecimal needToRefundAmount = null;
                    if (remainRefundAmount.compareTo(payDto.getPayAmount()) > 0) {
                        needToRefundAmount = payDto.getPayAmount();
                    } else {
                        needToRefundAmount = remainRefundAmount;
                    }
                    remainRefundAmount = remainRefundAmount.subtract(needToRefundAmount);
                    Integer paymentAmountType = payDto.getPaymentAmountType();
                    RefundPayDO refundPay = new RefundPayDO();
                    refundPay.setPayNo(payDto.getPayNo());
                    refundPay.setCurrency(payDto.getCurr());
                    refundPay.setRefundAmount(needToRefundAmount);
                    refundPay.setBankCode(payDto.getBankCode());
                    refundPay.setCreateDtm(new Date());
                    refundPay.setStatus(1);
                    refundPay.setUpdateDtm(new Date());
                    refundPay.setChannelCode(payDto.getChannel());
                    refundPay.setSite(payDto.getSite());
                    /**
                     * 新入库语言，国家字段
                     * by wangmc
                     * 2018.06.14
                     */
                    ChannelManageDto channelManageDto = ChannelUtil.findChannelByChannelCode(payDto.getChannel());
                    if (channelManageDto == null){
                        logger.error("Query channel Info error,channelNo:{}",payDto.getChannel());
                        continue;
                    }
                    String language = channelManageDto.getLanguageCode();
                    String country = channelManageDto.getNationCode();
                    refundPay.setLanguage(language);
                    refundPay.setCountry(country);
                    String refundPayNo = CeairUtil.compressLongNo(new BigInteger(payDto.getOrderNo() + new Date().getTime() + ""));
                    refundPay.setRefundPayNo(refundPayNo);
                    refundPay.setPayType(payDto.getPayTp());
                    refundPay.setRefundType(refundType);
                    refundPay.setOrderNo(payDto.getOrderNo());
                    refundPay.setPaySuccessNo(payDto.getPaySuccessNo());
                    if (paymentAmountType != null && paymentAmountType == 1) {
                        refundPay.setPaySuccessNo(payDto.getPaySuccessNoCash());
                    }
                    refundPay.setRemark(payDto.getCreateId());
                    refundPay.setRefundApplyDate(refundApply.getCreatDate());
                    refundPay.setRefundApplyId(refundApply.getId() + "");
                    refundPay.setDeleted(0);
                    refundPay.setSccode(payDto.getSccode());
                    refundPay.setSubsccode(payDto.getSubsccode());
                    refundPay.setPccode(payDto.getPccode());
                    refundPay.setSubpccode(payDto.getSubpccode());
                    refundPay.setOrgscdate(sdf.format(payDto.getPayRequestDt()));
                    refundPay.setVersion(0l);
                    refundPay.setPay(payDO);
                    boolean isPass = checkRefundPay(refundPay);
                    if (!isPass){
                        logger.error("refundPay check fail,refundApplyId:{}",refundApply.getId());
                        continue;
                    }
                    refundApplyIdList.add(refundApply.getId());
                    logger.info("机票订单编号：" + flightOrderNo + "退票订单号：" + refundApply.getId() + "退单号：" + refundPayNo);
                    refundPays.add(refundPay);
                    if (remainRefundAmount.compareTo(new BigDecimal("0")) <= 0) {
                        break;
                    }
                }
            }
            if (refundApply.getRefundPoints() != null && refundApply.getRefundPoints() > 0) {
                BigDecimal remainRefundPoint = new BigDecimal(refundApply.getRefundPoints());
                for (int j = 0; j < needToRefundPayDtoList.size(); j++) {
                    PayDO payDto = needToRefundPayDtoList.get(j);
                    PayDO payDO = (PayDO) BeanCopyUtils.copy(payDto, PayDO.class);
                    BigDecimal needToRefundPoint = null;
                    if (remainRefundPoint.compareTo(payDto.getPointAmount()) > 0) {
                        needToRefundPoint = payDto.getPointAmount();
                    } else {
                        needToRefundPoint = remainRefundPoint;
                    }
                    remainRefundPoint = remainRefundPoint.subtract(needToRefundPoint);
                    Integer paymentAmountType = payDto.getPaymentAmountType();
                    RefundPayDO refundPay = new RefundPayDO();
                    refundPay.setPayNo(payDto.getPayNo());
                    refundPay.setCurrency("PIT");
                    refundPay.setRefundAmount(needToRefundPoint);
                    refundPay.setBankCode(payDto.getBankCode());
                    refundPay.setCreateDtm(new Date());
                    refundPay.setStatus(1);
                    refundPay.setUpdateDtm(new Date());
                    refundPay.setChannelCode(payDto.getChannel());
                    refundPay.setSite(payDto.getSite());
                    String refundPayNo = CeairUtil.compressLongNo(new BigInteger(payDto.getOrderNo() + new Date().getTime() + ""));
                    refundPay.setRefundPayNo(refundPayNo);
                    refundPay.setPayType(payDto.getPayTp());
                    refundPay.setRefundType(refundType);
                    refundPay.setOrderNo(payDto.getOrderNo());
                    refundPay.setPaySuccessNo(payDto.getPaySuccessNo());
                    if (paymentAmountType != null && paymentAmountType == 1) {
                        refundPay.setPaySuccessNo(payDto.getPaySuccessNoPoint());
                    }
                    refundPay.setRemark(payDto.getCreateId());
                    refundPay.setRefundApplyDate(refundApply.getCreatDate());
                    refundPay.setRefundApplyId(refundApply.getId() + "");
                    refundPay.setDeleted(0);
                    refundPay.setSccode(payDto.getSccode());
                    refundPay.setSubsccode(payDto.getSubsccode());
                    if (paymentAmountType != null && paymentAmountType == 1) {
                        refundPay.setPccode(payDto.getPccodePoint());
                        refundPay.setSubpccode(payDto.getSubpccodePoint());
                    }
                    refundPay.setOrgscdate(sdf.format(payDto.getPayRequestDt()));
                    refundPay.setVersion(0l);
                    refundPay.setPay(payDO);
                    //TODO
                    boolean isPass = checkRefundPay(refundPay);
                    if (!isPass){
                        logger.error("refundPay check fail,refundApplyId:{}",refundApply.getId());
                        continue;
                    }
                    refundApplyIdList.add(refundApply.getId());
                    logger.info("机票订单编号：" + flightOrderNo + "退票订单号：" + refundApply.getId() + "退单号：" + refundPayNo);
                    refundPays.add(refundPay);
                    if (remainRefundPoint.compareTo(new BigDecimal("0")) <= 0) {
                        break;
                    }
                }
            }
        }
        logger.info("插入退款表中开始。。。");
        if (!refundPays.isEmpty()) {
            refundPayDao.batchInsertRfdPay(refundPays);
            logger.info("插入退款表中完成。。。");
        }
        logger.info("退票单状态更新402开始！");
        if (!refundApplyIdList.isEmpty()) {
            float size = 999;
            float times = refundApplyIdList.size() / size;
            for (int i = 0; i < times; i++) {
                float start = i * size;
                float end = (i + 1) * size;
                if (end >= refundApplyIdList.size()) {
                    end = refundApplyIdList.size();
                }
                List<Long> subList = refundApplyIdList.subList((int) start, (int) end);
                List<Object[]> objects = new ArrayList<>();
                for (Long appId:subList){
                    Object[] arr = new Object[3];
                    arr[0] = "402";
                    arr[1] = new Date();
                    arr[2] = appId;
                    objects.add(arr);
                }
                String sql = "update  T_REFUND_APPLY set STATUS=?,UPDAT_DATE=? where ID = ? ";
                dbUtil.batchUpdate(sql,objects);
                logger.info("退票单" + refundApplyIdList + "状态更新402成功！");
            }
        }
    }

    private void getNeedToRefundPayDto(String flightOrderNo, List<PayDO> needToRefundPayDtoList) {
        PayProductDto payProduct = new PayProductDto();
        payProduct.setProductId(flightOrderNo);
        List<PayDO> payDtoList = payDao.getPayDOAndPayProductDOList(payProduct);
        if (payDtoList != null && payDtoList.size() > 0) {
            Collections.sort(payDtoList, new Comparator<PayDO>() {

                @Override
                public int compare(PayDO o1, PayDO o2) {
                    return o1.getId().intValue() - o2.getId().intValue();
                }
            });
            List<String> orderProductList = new ArrayList<>();
            for (int j = 0; j < payDtoList.size(); j++) {
                PayDO payDto = payDtoList.get(j);
                //只有支付成功或者风控人工审核失败的才会退款
                if (payDto.getPaySt().intValue() == PaymentStatusEnum.PAY_SUCCESS.getCode().intValue()
                        || (payDto.getPaySt().intValue() == PaymentStatusEnum.PAY_FAILURE.getCode().intValue() && PayResponseCodeEnum.RISK_FAILURE.getCode().equals(payDto.getRespCode()))) {
                    String orderProductIds = payDto.getOrderProductIds();
                    if (orderProductList.contains(orderProductIds)) {
                        continue;
                    }
                    orderProductList.add(orderProductIds);
                    needToRefundPayDtoList.add(payDto);
                }
            }
        }
    }

    /**
     *
     * @param refundApplyDto 退辅营
     */
    private void doBatchRefundPayAncillary(RefundApplyDto refundApplyDto) {
        RefundApplyDeputyDto refundApplyDeputyDto1 = new RefundApplyDeputyDto();
        refundApplyDeputyDto1.setStatuses(refundApplyDto.getStatuses());
        List<RefundApplyDeputyDto> refundApplyDeputyDtoList = refundApplyDeputyDao.getRefundApplyDeputyList(refundApplyDeputyDto1);
        if (refundApplyDeputyDtoList == null || refundApplyDeputyDtoList.isEmpty()) {
            logger.info("没有可退款的辅营退票单！");
            return;
        }
        List<Long> refundApplyIdList = new ArrayList<Long>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        List<RefundPayDO> refundPays = new ArrayList<RefundPayDO>();
        PayProductDto payProductDto = new PayProductDto();
        for (int i = 0; i < refundApplyDeputyDtoList.size(); i++) {
            RefundApplyDeputyDto refundApplyDeputyDto = refundApplyDeputyDtoList.get(i);
            String deputyType = refundApplyDeputyDto.getDeputyType();
            Integer refundType = 0;
            if ("10".equals(deputyType)) {//WIFI
                refundType = RefundTypeEnum.REFUND_WIFI.getCode();
            } else if ("11".equals(deputyType)) {//VIP
                refundType = RefundTypeEnum.REFUND_VIP.getCode();
            } else if ("12".equals(deputyType)) {//选座
                refundType = RefundTypeEnum.REFUND_EMD.getCode();
            } else if ("13".equals(deputyType)) {//行李
                refundType = RefundTypeEnum.REFUND_BAGE.getCode();
            } else if ("17".equals(deputyType)) {//高铁
                refundType = RefundTypeEnum.REFUND_GAOTIE.getCode();
            } else {
                if (StringUtil.isBlank(deputyType)){
                    continue;
                }
                refundType = Integer.parseInt(deputyType);
            }
            String productId = refundApplyDeputyDto.getProductOrderId();
            payProductDto.setProductId(productId);
            //payProductDto.setPaySt(40);
            List<PayDO> payDtoList = payDao.getPayDOAndPayProductDOList(payProductDto);
            Collections.sort(payDtoList, new Comparator<PayDO>() {

                @Override
                public int compare(PayDO o1, PayDO o2) {
                    return o1.getId().intValue() - o2.getId().intValue();
                }
            });
            List<String> orderProductList = new ArrayList<String>();
            if (payDtoList != null && payDtoList.size() > 0) {
                for (int j = 0; j < payDtoList.size(); j++) {
                    PayDO payDto = payDtoList.get(j);
                    PayDO payDO = (PayDO) BeanCopyUtils.copy(payDto, PayDO.class);
                    Integer paymentAmountType = payDto.getPaymentAmountType();
                    //只有支付成功或者风控人工审核失败的才会退款
                    if (payDto.getPaySt().intValue() == PaymentStatusEnum.PAY_SUCCESS.getCode().intValue()
                            || (payDto.getPaySt().intValue() == PaymentStatusEnum.PAY_FAILURE.getCode().intValue() && PayResponseCodeEnum.RISK_FAILURE.getCode().equals(payDto.getRespCode()))) {
                        String orderProductIds = payDto.getOrderProductIds();
                        if (orderProductList.contains(orderProductIds)) {
                            continue;
                        }
                        orderProductList.add(orderProductIds);
                        if (refundApplyDeputyDto.getRefundAmount() != null && refundApplyDeputyDto.getRefundAmount().compareTo(BigDecimal.ZERO) > 0) {
                            RefundPayDO refundPay = new RefundPayDO();
                            refundPay.setPayNo(payDto.getPayNo());
                            refundPay.setCurrency(payDto.getCurr());
                            refundPay.setRefundAmount(refundApplyDeputyDto.getRefundAmount());
                            refundPay.setBankCode(payDto.getBankCode());
                            refundPay.setCreateDtm(new Date());
                            refundPay.setStatus(1);
                            refundPay.setUpdateDtm(new Date());
                            refundPay.setChannelCode(payDto.getChannel());
                            refundPay.setSite(payDto.getSite());
                            /**
                             * 新入库语言，国家字段
                             * by wangmc
                             * 2018.06.14
                             */
                            ChannelManageDto channelManageDto = ChannelUtil.findChannelByChannelCode(payDto.getChannel());
                            if (channelManageDto == null){
                                logger.error("Query channel Info error,channelNo:{}",payDto.getChannel());
                                continue;
                            }
                            String language = channelManageDto.getLanguageCode();
                            String country = channelManageDto.getNationCode();
                            refundPay.setLanguage(language);
                            refundPay.setCountry(country);
                            String refundPayNo = CeairUtil.compressLongNo(new BigInteger(payDto.getOrderNo() + new Date().getTime() + ""));
                            refundPay.setRefundPayNo(refundPayNo);
                            refundPay.setPayType(payDto.getPayTp());
                            refundPay.setRefundType(refundType);
                            refundPay.setOrderNo(payDto.getOrderNo());
                            refundPay.setPaySuccessNo(payDto.getPaySuccessNo());
                            if (paymentAmountType != null && paymentAmountType == 1) {
                                refundPay.setPaySuccessNo(payDto.getPaySuccessNoCash());
                            }
                            refundPay.setRemark("批量退款");
                            refundPay.setRefundApplyDate(refundApplyDeputyDto.getCreatDate());
                            refundPay.setRefundApplyId(refundApplyDeputyDto.getId() + "");
                            refundPay.setDeleted(0);
                            refundPay.setSccode(payDto.getSccode());
                            refundPay.setSubsccode(payDto.getSubsccode());
                            refundPay.setPccode(payDto.getPccode());
                            refundPay.setSubpccode(payDto.getSubpccode());
                            refundPay.setOrgscdate(sdf.format(payDto.getPayRequestDt()));
                            refundPay.setVersion(0l);
                            refundPay.setPay(payDO);
                            boolean isPass = checkRefundPay(refundPay);
                            if (!isPass){
                                continue;
                            }
                            refundApplyIdList.add(refundApplyDeputyDto.getId());
                            logger.info("机票订单编号：" + productId + "退票订单号：" + refundApplyDeputyDto.getId() + "退单号：" + refundPayNo);
                            refundPays.add(refundPay);
                        }
                        break;
                    }
                }
            }
        }
        logger.info("插入退款表中开始。。。");
        if (!refundPays.isEmpty()) {
            refundPayDao.batchInsertRfdPay(refundPays);
            logger.info("插入退款表中完成。。。");
        }
        logger.info("退票单状态更新402开始！");
        if (!refundApplyIdList.isEmpty()) {
            float size = 999;
            float times = refundApplyIdList.size() / size;
            for (int i = 0; i < times; i++) {
                float start = i * size;
                float end = (i + 1) * size;
                if (end >= refundApplyIdList.size()) {
                    end = refundApplyIdList.size();
                }
                List<Long> subList = refundApplyIdList.subList((int) start, (int) end);
                List<Object[]> objects = new ArrayList<>();
                for (Long appId:subList){
                    Object[] arr = new Object[3];
                    arr[0] = "402";
                    arr[1] = new Date();
                    arr[2] = appId;
                    objects.add(arr);
                }
                String sql = "update  T_REFUND_APPLY_DEPUTY set STATUS=?,UPDATE_DATE=? where ID = ? ";
                dbUtil.batchUpdate(sql,objects);
                logger.info("退票单" + refundApplyIdList + "状态更新402成功！");
            }
        }
    }

    private boolean checkRefundPay(RefundPayDO refundPay) {
        boolean result = false;
        if (!StringUtil.isBlank(refundPay.getPayNo())){
            if (!StringUtil.isBlank(refundPay.getCurrency())){
                if (refundPay.getRefundAmount() !=null){
                    if (!StringUtil.isBlank(refundPay.getRefundPayNo())){
                        if (!StringUtil.isBlank(refundPay.getSccode())){
                            if (!StringUtil.isBlank(refundPay.getSubsccode())){
                                if (!StringUtil.isBlank(refundPay.getPccode())){
                                    if (!StringUtil.isBlank(refundPay.getSubpccode())) {
                                        if (!StringUtil.isBlank(refundPay.getOrgscdate())){
                                            result = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return result;
    }
}
